<template>
	<view class="jnpf-wrap jnpf-wrap-workflow">
		<u-form :model="info" :errorType="['toast']" label-position="left" label-width="150" label-align="left">
			<u-form-item v-if="judgeShow('creator')" label="录入人员">
				<u-input v-model="info.creator" placeholder="请输入录入人员" disabled></u-input>
			</u-form-item>

			<u-form-item v-if="judgeShow('createName')" label="录入名称">
				<u-input v-model="info.createName" placeholder="请输入录入名称" disabled></u-input>
			</u-form-item>

			<u-form-item v-if="judgeShow('createDate')" label="录入日期">
				<u-input v-model="info.createDate" placeholder="请输入录入日期" disabled></u-input>
			</u-form-item>

			<u-form-item v-if="judgeShow('taskId')" label="单号">
				<u-input v-model="info.taskId" placeholder="请输入单号" disabled></u-input>
			</u-form-item>

			<u-form-item v-if="judgeShow('ma001')" label="供应商编号">
				<u-input v-model="info.ma001" placeholder="请输入供应商编号" disabled></u-input>
			</u-form-item>

			<u-form-item v-if="judgeShow('ma002')" label="供应商简称">
				<u-input v-model="info.ma002" placeholder="请输入供应商简称" disabled></u-input>
			</u-form-item>

			<u-form-item v-if="judgeShow('ma003')" label="供应商全称">
				<u-input v-model="info.ma003" placeholder="请输入供应商全称" disabled></u-input>
			</u-form-item>

			<u-form-item v-if="judgeShow('ma065')" label="快捷码">
				<u-input v-model="info.ma065" placeholder="请输入快捷码" disabled></u-input>
			</u-form-item>

			<u-form-item v-if="judgeShow('ma005')" label="税号">
				<u-input v-model="info.ma005" placeholder="请输入税号" disabled></u-input>
			</u-form-item>

			<u-form-item v-if="judgeShow('ma017')" label="开业日">
				<u-input v-model="info.ma017" placeholder="请输入开业日" disabled></u-input>
			</u-form-item>

			<u-form-item v-if="judgeShow('ma012')" label="负责人">
				<u-input v-model="info.ma012" placeholder="请输入负责人" disabled></u-input>
			</u-form-item>

			<u-form-item v-if="judgeShow('ma013')" label="联系人">
				<u-input v-model="info.ma013" placeholder="请输入联系人" disabled></u-input>
			</u-form-item>

			<u-form-item v-if="judgeShow('ma078')" label="电话">
				<u-input v-model="info.ma078" placeholder="请输入电话" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('ma010')" label="传真">
				<u-input v-model="info.ma010" placeholder="请输入传真" disabled></u-input>
			</u-form-item>

			<u-form-item v-if="judgeShow('ma011')" label="E_mail">
				<u-input v-model="info.ma011" placeholder="请输入您的邮箱" disabled></u-input>
			</u-form-item>

			<u-form-item v-if="judgeShow('ma019')" label="员工人数">
				<u-input v-model="info.ma019" placeholder="请输入员工人数" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('ma018')" label="注册资金">
				<u-input v-model="info.ma018" placeholder="请输入注册资金" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('ma021')" label="交易币种">
				<u-input v-model="moneyTypeName" placeholder="请输入交易币种" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('ma044')" label="税种">
				<u-input v-model="categoriesOfTaxesName" placeholder="请输入税种" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('ma055')" label="付款条件">
				<u-input v-model="payUse" placeholder="请输入付款条件" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('ma028')" label="汇款账号">
				<u-input v-model="info.ma028" placeholder="请输入汇款账号" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('ma024')" label="结算方式">
				<u-input v-model="piaojuName" placeholder="请输入结算方式" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('ma030')" label="发票种类">
				<u-input v-model="faPiaoClass" placeholder="请输入发票种类" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('ma064')" label="税率">
				<u-input v-model="info.ma064" placeholder="请输入税率" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('ma004')" label="供应商分类">
				<u-input v-model="className" placeholder="请输入供应商分类" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('udf04')" label="品质主管">
				<u-input v-model="buyNameThree" placeholder="请输入品质主管" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('udf03')" label="研发主管">
				<u-input v-model="info.udf03" placeholder="请输入研发主管" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('ma047')" label="采购人员">
				<u-input v-model="buyName" placeholder="请输入采购人员" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('ma014')" label="公司地址">
				<u-input v-model="info.ma014" placeholder="请输入公司地址" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('businesslicense')" label="营业执照">
				<jnpf-file v-model="info.businesslicense" disabled />
			</u-form-item>
			<u-form-item v-if="judgeShow('qualitycertification')" label="有无ISO品">
				<jnpf-file v-model="info.qualitycertification" disabled />
			</u-form-item>
			<u-form-item v-if="judgeShow('supplier')" label="供应商评分">
				<jnpf-file v-model="info.supplier" disabled />
			</u-form-item>
		</u-form>
	</view>
</template>

<script>
	import comMixin from '../mixin'
	import {
		getGoodsList,
		getCustomerList,
		Info,
		Create,
		Update,
	} from '@/api/apply/order'
	import {
		getYyPurmaInfo
	} from '@/api/workFlow/flowEngine'
	import {
		getDictionaryDataSelector,
		getDataInterfaceDataInfo,
		getDataInterfaceRes
	} from '@/api/common'
	export default {
		mixins: [comMixin],
		data() {
			return {
				buyName: '',
				buyNameTwo: '',
				buyNameThree: '',
				buyNameFour: '',
				info: {},
				lst: [],
				id: '',
				value13: false,
				dataForm: {},
				purtfList: [],
				itemLst: [],
				userName: '',
				goChangeName: '',
				moneyName: '',
				moneyTypeName: '',
				payUse: "",
				className: "",
				piaojuName: '',
				categoriesOfTaxesName: '', //税种
				faPiaoClass: '', //税种
			}
		},
		methods: {
			init(data, id) {
				this.id = id
				this.setting = data
				this.getInfoFn(data)
			},
			getInfoFn(data) {
				getYyPurmaInfo(data.id).then(res => {
					if (res.code == 200) {
						this.info = res.data
						this.info.ma001 = this.info.ma001 || '系统自动生成'
						this.info.createDate = this.info.createDate.substr(0, 8)
						this.getDictionaryDataSelectorFn()
						this.getDictionaryDataSelectorTwoFn()
						this.getDataInterfaceResFn()
						this.getDataInterfaceResOne()
						this.getDataInterfaceResTwo()
						this.getDataInterfaceResThree()
						this.getDataInterfaceDataInfoMV002(this.info.ma047)
						this.getDataInterfaceDataInfoMV003(this.info.udf04)
					 
						// this.getDataInterfaceDataInfoGoChange(this.info.te039)
						// this.getDataInterfaceDataInfoGoMoneyType(this.info.te007)
						// this.getDataInterfaceDataInfoGoPayType(this.info.te023)
						// this.getCangKu(this.itemLst[0].tf008)
					}
				})
			},
			getDataInterfaceResFn() {
				getDataInterfaceRes('362115609221143109').then(res => {
					if (res.code == 200) {
						res.data.data.forEach(res => {
							if (res.MF001 == this.info.ma021) {
								this.moneyTypeName = res.JoinStr
							}
						})
					}
				})
			},
			getDataInterfaceResOne() {
				getDataInterfaceRes('412854877157414213').then(res => {
					if (res.code == 200) {
						res.data.data.forEach(res => {
							if (res.NJ001 == this.info.ma024) {
								this.piaojuName = res.JoinStr
							}
						})
					}
				})
			},
			getDataInterfaceResTwo() {
				getDataInterfaceRes('362115953258928709').then(res => {
					if (res.code == 200) {
						res.data.data.forEach(res => {
							if (res.NA002 == this.info.ma055) {
								this.payUse = res.JoinStr
							}
						})
					}
				})
			},

			getDataInterfaceResThree() {
				getDataInterfaceRes('489571656965099525').then(res => {
					if (res.code == 200) {
						res.data.data.forEach(res => {
							if (res.MR002 == this.info.ma004) {
								this.className = res.JoinStr
							}
						})
					}
				})
			},
			/**
			 * 查询税种列表
			 */
			getDictionaryDataSelectorFn() {
				getDictionaryDataSelector('411695330707391429').then(res => {
					if (res.code == 200) {
						res.data.list.forEach(res => {
							if (res.enCode == this.info.ma044) {
								this.categoriesOfTaxesName = res.fullName
							}
						})
					}
				})
			},
			getDictionaryDataSelectorTwoFn() {
				getDictionaryDataSelector('382030349477096325').then(res => {
					if (res.code == 200) {
						res.data.list.forEach(res => {
							if (res.enCode == this.info.ma030) {
								this.faPiaoClass = res.fullName
							}
						})
					}
				})
			},
			getDataInterfaceDataInfoMV002(id) {
				let data = {
					id,
					interfaceId: '428345732257285957',
					dblink: '',
					propsValue: 'MV001',
					relationField: 'JoinStr',
				}
				getDataInterfaceDataInfo('428345732257285957', data).then(res => {
					console.log('getDataInterfaceDataInfo res', res)
					if (res.code == 200) {
						this.buyName = res.data.JoinStr
					}
				})
			},
			getDataInterfaceDataInfoMV003(id) {
				let data = {
					id,
					interfaceId: '468417808561087429',
					dblink: '',
					propsValue: 'Id',
					relationField: 'DisplayName',
				}
				getDataInterfaceDataInfo('468417808561087429', data).then(res => {
					if (res.code == 200) {
						this.buyNameThree = res.data.DisplayName
					}
				})
			},
			selfGetInfo() {
				Info(this.setting.id).then(res => {
					this.dataForm = res.data
					if (this.dataForm.fileJson) {
						this.fileList = JSON.parse(this.dataForm.fileJson)
					}
				})
			},
			getCangKu(id) {
				let data = {
					id,
					interfaceId: '381218413038545541',
					propsValue: 'MC001',
					dblink: this.id,
					relationField: 'JoinStr',
				}
				getDataInterfaceDataInfo('381218413038545541', data).then(res => {
					if (res.code == 200) {
						this.cangkuName = res.data.JoinStr
					}
				})
			},
			test(id) {
				let data = {
					id,
					interfaceId: '381218413038545541',
					propsValue: 'MC001',
					dblink: this.id,
					relationField: 'JoinStr',
				}

				getDataInterfaceDataInfo('381218413038545541', data).then(res => {
					if (res.code == 200) {
						resolve(res.data.JoinStr)
					} else {
						reject('')
					}
				})

			},
			selfSubmit() {
				this.dataForm.status = this.eventType === 'submit' ? 0 : 1
				if (this.eventType === 'save') return this.selfHandleRequest()
				uni.showModal({
					title: '提示',
					content: '您确定要提交当前流程吗？',
					success: res => {
						if (res.confirm) {
							this.selfHandleRequest()
						}
					}
				})
			},
			selfHandleRequest() {
				if (!this.dataForm.id) delete(this.dataForm.id)
				const formMethod = this.dataForm.id ? Update : Create
				formMethod(this.dataForm).then(res => {
					uni.showToast({
						title: res.msg,
						complete: () => {
							setTimeout(() => {
								uni.$emit('refresh')
								uni.navigateBack()
							}, 1500)
						}
					})
				})
			},
			initData() {
				getGoodsList().then(res => {
					this.goodsOptions = res.data.list
				})
				getCustomerList().then(res => {
					this.customerOptions = res.data.list
				})
			},
			selfInit() {
				this.addGoods()
				this.addPlan()
			},
			onChange(e) {
				const user = e[0]
				this.dataForm.salesmanName = user.fullName
			},
			addGoods() {
				const item = {
					goodsId: '',
					goodsCode: '',
					goodsName: '',
					specifications: '',
					unit: '',
					qty: '',
					price: '',
					amount: '',
					discount: null,
					cess: null,
					actualPrice: '',
					actualAmount: '',
					description: ''
				}
				this.dataForm.goodsList.push(item)
			},
			delGoods(index) {
				this.dataForm.goodsList.splice(index, 1)
			},
			addPlan() {
				const item = {
					receivableDate: '',
					receivableRate: '',
					receivableMoney: '',
					receivableMode: '',
					abstract: ''
				}
				this.dataForm.collectionPlanList.push(item)
			},
			delPlan(index) {
				this.dataForm.collectionPlanList.splice(index, 1)
			},
			onGoodsChange(e, i) {
				const goods = e[0]
				this.dataForm.goodsList[i] = {
					goodsId: goods.id,
					goodsCode: goods.code,
					goodsName: goods.text,
					specifications: goods.specifications,
					unit: goods.unit,
					qty: 1,
					price: goods.price,
					amount: goods.price,
					discount: 100,
					cess: 0,
					actualPrice: goods.price,
					actualAmount: goods.price,
					description: ''
				}
				this.$forceUpdate()
			},
			onCustomerChange(e) {
				const customer = e[0]
				this.dataForm.customerName = customer.text
			},
			count(row) {
				//金额 = 数量*单价
				row.amount = this.jnpf.toDecimal(parseFloat(row.price) * parseFloat(row.qty))
				//折扣价 = (单价*折扣)
				var discountPrice = row.price * (row.discount / 100);
				//实际单价 = 折扣价 * (1 + (税率 / 100))
				row.actualPrice = this.jnpf.toDecimal(discountPrice * (1 + (row.cess / 100)));
				//实际金额
				row.actualAmount = this.jnpf.toDecimal(parseFloat(row.actualPrice) * parseFloat(row
					.qty))
				this.$forceUpdate()
			}
		}
	}
</script>